#include "gizmos.h"

#include "gizmos_renderer.h"
const size_t GizmosRenderer::RenderBatch::MAX_VERTEX_NUM = 3000;
const size_t GizmosRenderer::RenderBatch::MAX_INDEX_NUM = 1000;
GizmosRenderer::RenderBatch::RenderBatch(const GizmosRenderer::BatchContainer* container)
    : vao(csugl::VertexArray::Creat()), indices_offset(0) {
    vao->SetIndexBuffer(csugl::IndexBuffer::Create<uint32_t>(6 * MAX_INDEX_NUM));
    vao->AddVertexBuffer(container->vbo, {
        {csugl::BufferElementType::Float2},
        {csugl::BufferElementType::Float3},
    });
}
const size_t GizmosRenderer::BatchContainer::MAX_BATCH_SIZE = 20;
GizmosRenderer::BatchContainer::BatchContainer() 
    : vbo(csugl::VertexBuffer::Create<float>(
        5 * MAX_BATCH_SIZE * GizmosRenderer::RenderBatch::MAX_VERTEX_NUM)) {
}

void GizmosRenderer::init() {
}

void GizmosRenderer::submit(csugl::Ref<csugl::Shader> shader, csugl::Ref<Square> square) {
    // 1. get cur_container through top_container
    // 2. get cur_batch through cur_container->top_batch
    // 3. if it has not been exceed yet
        // 4. get indices_offset from cur_batch
    // 4. else
    const auto& sq_size = square->size;
    const auto& sq_pos = square->position + square->origin;
    float vert[20] = {
        sq_pos.x - sq_size, sq_pos.y - sq_size,
            square->color.r, square->color.g, square->color.b,
        sq_pos.x - sq_size, sq_pos.y + sq_size,
            square->color.r, square->color.g, square->color.b,
        sq_pos.x + sq_size, sq_pos.y + sq_size,
            square->color.r, square->color.g, square->color.b,
        sq_pos.x + sq_size, sq_pos.y - sq_size,
            square->color.r, square->color.g, square->color.b,
    };
    uint32_t indi_offset = 0;
    uint32_t indi[6] = {
        indi_offset + 0, indi_offset + 1, indi_offset + 2,
        indi_offset + 0, indi_offset + 2, indi_offset + 3,
    };
}
